package edu.gdkm.demo12;

import java.util.*;

public class ListTest2 {
    public static void main(String[] args) {
        List<Integer> list1 =new ArrayList<>();
        for(int i=0;i<10;i++){
            list1.add(new Random().nextInt(100));
        }
        //浅拷贝
        List<Integer> list2=list1;
        System.out.println("list1:"+list1);
        System.out.println("list2:"+list2);
        //移除list1中的第一个元素
        list1.remove(0);
        System.out.println("list1:"+list1);
        System.out.println("list2:"+list2);

        //创建list3时，因为需要深拷贝，所以需要设置其长度与list1相同，
        List<Integer> list3=new ArrayList<>(Arrays.asList(new Integer[list1.size()]));
        //深拷贝
        Collections.copy(list3,list1);
        System.out.println("list1:"+list1);
        System.out.println("list3:"+list3);
        list1.remove(0);
        System.out.println("list1:"+list1);
        System.out.println("list3:"+list3);
    }
}
